//=============================================================================
/**
 * @file	pokethlon.h
 * @brief	ポケスロン
 * @date	2007.07.10
 */
//=============================================================================

#ifndef	__POKETHLON_H__
#define	__POKETHLON_H__

typedef struct POKETHLON_WORK_tag * PKTHLN_PTR;

#include "pokethlon_common.h"
#include "pkthln_comm_pack.h"
#include "result_data.h"

#include "poke_clact_def.h"

#include "cmn_res.h"
#include "pkthln_event/pkthln_clact.h"
#include "savedata/pkthln_svdata.h"

#include "pkthln_poke_act.h"

#include "pkthln_event/point_calc.h"

#define ENTRY_MEMBER_NUM_MAX	(4)
#define EVT_SCORE_MAX	(999)

#define WIN_REC_PX		(0)
#define WIN_REC_PY		(20)
#define WIN_REC_SX		(32)
#define WIN_REC_SY		(2)


typedef enum{
	PTH_RC_LOOP,			//通信・非通信にかかわらず、処理をメインフレームに返す
//	PTH_RC_COMM_LOOP,		//通信時のみ、処理をメインフレームに返す
	PTH_RC_END,				//処理終了
}PTH_RC;

typedef struct HIT_DATA_tag
{
	int Ofs;
	int Range;
}HIT_DATA;

typedef struct EVT_HIT_DATA_tag
{
	HIT_DATA Data[3];
}EVT_HIT_DATA;

typedef enum{
	HIT_TYPE_NONE,
	HIT_TYPE_A,
	HIT_TYPE_B,
	HIT_TYPE_C
}HIT_TYPE;

typedef enum{
	TOUCH_TYPE_NONE,
	TOUCH_TYPE_A,
	TOUCH_TYPE_B,
	TOUCH_TYPE_C
}TOUCH_TYPE;

typedef enum{
	SHADOW_TYPE_NONE,
	SHADOW_TYPE_A,
	SHADOW_TYPE_B,
	SHADOW_TYPE_C
}SHADOW_TYPE;

typedef enum{
	ADD_TYPE_TOUCH,
	ADD_TYPE_FAIL,
	ADD_TYPE_JUMP,
	ADD_TYPE_GET,
	ADD_TYPE_ATTACK,
	ADD_TYPE_FALL,
	ADD_TYPE_DASH,
	ADD_TYPE_CHANGE,
	ADD_TYPE_OWN,
}ACTION_ADD_TYPE;

typedef struct PKTHLN_POKE_RSLT_tag
{
	u32 Fail;
	u32 Jump;
	u32 Get;
	u32 Attack;
	u32 Fall;
	u32 Dash;
	u32 Change;
	u32 OwnGoal;
}PKTHLN_POKE_RSLT;		//32Byte

//セーブとかするために必要
typedef struct PKTHLN_TEMP_DATA_tag
{
	//親が後で子に送信
	PKTHLN_POKE_RSLT PokeRslt[ENTRY_MEMBER_NUM_MAX][ENTRY_MAX];
	//ローカルで取得可
///	u32 CourseID;					//コースＩＤ
///	u32 PlayStart;					//開始時間
///	u32 PlayEnd;					//終了時間
	u32 BonusNum;					//[out] 今回のボーナス取得回数
	u32 Touch;						//スクリーンタッチ数

	u16 EvtScore[ENTRY_MEMBER_NUM_MAX][COMM_EVT_MAX];		//全チームの競技得点
	u16 EvtRecord[ENTRY_MEMBER_NUM_MAX][COMM_EVT_MAX];	//全チームの全競技のレコード
	u8 EvtWin[COMM_EVT_MAX];		//競技で優勝した？
	u8 EvtLose[COMM_EVT_MAX];	//競技で最下位？

	u16 CrsWin:1;						//[out] コース優勝？
	u16 CrsLose:1;						//[out] コース最下位
	u16 Rank:2;							//[out]	最終的な順位
	u16 dummy:4;
	u16 RsltScore;					//[out] 最終スコア
}PKTHLN_SVSET_DATA;


//ペンアクター表示位置構造体
typedef struct PEN_POS_tag
{
	u16 X;
	u16 Y;
}PEN_POS;

typedef void PTH_EVENT_WORK;
typedef PTH_RC (*PTH_INIT_FUNC)(PKTHLN_PTR, void *);
typedef BOOL (*PTH_FUNC)(PKTHLN_PTR, void *);

typedef BOOL (*PKTHLN_FUNC)(PKTHLN_PTR work, u8 *seq);

typedef void (*REC_CALL_BACK)(PKTHLN_PTR work);

//--------------------------------------------------------------
///	FIELD_OBJ_MOVE_PROC_LIST構造体
//--------------------------------------------------------------
#if 0
typedef struct POKETHLON_FUNC_TBL_tag
{
	PTH_INIT_FUNC InitFunc;						///<初期化関数
	PTH_FUNC InputFunc;							///<動作入力関数
	PTH_FUNC ReceiveFunc;						///<データレシーヴ関数
	PTH_FUNC ParentFunc;						///<判定処理関数（通信では親のみ）
	PTH_FUNC DrawFunc;							///<描画関数
	PTH_FUNC EndCheckFunc;						///<終了チェック関数
	PTH_FUNC EndFunc;							///<終了関数
}POKETHLON_FUNC_TBL;
#else
typedef struct POKETHLON_FUNC_TBL_tag
{
	PTH_INIT_FUNC InitFunc;						///<初期化関数
	PTH_FUNC DrawFunc;							///<描画関数
	PTH_FUNC ResultFunc;						///<競技終了後処理関数
	PTH_FUNC EndFunc;							///<終了関数
	BOOL ResultSend;							///<アプリ結果を親に送る必要があるか？
}POKETHLON_FUNC_TBL;

#endif

extern u8 PTFrame_GetPlayerNum(PKTHLN_PTR work);
extern COMMON_PLAYER_DATA *PTFrame_GetCmnPlayerDataPtrByID(PKTHLN_PTR work, const int inID);
extern POKETHLON_ENTRY_DATA *PTFrame_GetEntryDataPtrByID(PKTHLN_PTR work, const int inID);
extern SAVEDATA	*PTFrame_GetSaveData(PKTHLN_PTR work);
extern PKTHLN_SVSET_DATA *PTFrame_GetSvSetDataPtr(PKTHLN_PTR work);
extern PKTHLN_POKE_RSLT *PTFrame_GetEvtActDataPtr(PKTHLN_PTR work, const u8 inNetID);
extern PKTHLN_POKE_RSLT *PTFrame_GetMyEvtActDataPtr(PKTHLN_PTR work);
///extern POKETHLON_ENTRY_DATA *PTFrame_GetEntryDataPtr(PKTHLN_PTR work);
extern PTH_EVENT_WORK * PTFrame_AllocEventWork(PKTHLN_PTR work, int size);
extern void PTFrame_FreeEventWork(PKTHLN_PTR work);
extern PTH_EVENT_WORK *PTFrame_GetEventWorkPtr(PKTHLN_PTR work);
extern int PTFrame_GetHeapID(PKTHLN_PTR work);
extern u8 PTFrame_GetSubSeq(PKTHLN_PTR work);
extern void PTFrame_SetSubSeq(PKTHLN_PTR work, const u8 inSeq);
extern void PTFrame_IncSubSeq(PKTHLN_PTR work);
extern void PTFrame_SetDraw(PKTHLN_PTR work, const BOOL inFlg);
extern void PTFrame_SetEventNo(PKTHLN_PTR work, const u8 *inEventList);
extern PKTHLN_EVT_CODE PTFrame_GetEventCode(PKTHLN_PTR work);
extern PKTHLN_EVT_CODE PTFrame_GetEventCodeByIdx(PKTHLN_PTR work, const u8 inIdx);
extern u8 PTFrame_GetCourseID(PKTHLN_PTR work);
extern int PTFrame_GetEventCounter(PKTHLN_PTR work);

extern PKTHLN_GAME_TYPE PTFrame_GetGameType( PKTHLN_PTR work );
extern u8 PTFrame_GetDataSendNum( PKTHLN_PTR work );
extern void PTFrame_AddDataSendNum( PKTHLN_PTR work );
extern void PTFrame_ClearDataSendNum( PKTHLN_PTR work );

extern COMMPACK_PTR PTFrame_GetCommPackPtr(PKTHLN_PTR work);
extern const int PTFrameGetCurrentID(PKTHLN_PTR work);
extern MYSTATUS *PTFrame_GetMyStatus(PKTHLN_PTR work, const int inID);
extern PKTH_RNK_DATA *PTFrame_GetRankDataPtr(PKTHLN_PTR work, const int inID);
///extern PKTH_RNK_DATA *PTFrame_GetOrgRankDataPtr(PKTHLN_PTR work);
extern COMM_EVENT_COMMON_DATA *PTFrame_GetEvtComCmnData(PKTHLN_PTR work);
extern void PTFrame_ClearEvtComCmnData(PKTHLN_PTR work);

extern void PTFrame_SetEvtShareDataPtr(PKTHLN_PTR work, void *send, void *recive, const int inSize );
extern void PTFrame_ClearEvtShareDataPtr(PKTHLN_PTR work);
extern void *PTFrame_GetEvtShareDataPtr(PKTHLN_PTR work);
extern int PTFrame_GetEvtShareDataSize(PKTHLN_PTR work);

extern int PTFrame_GetEvtResultDataSize(PKTHLN_PTR work);
extern void PTFrame_SetEvtResultOrg(PKTHLN_PTR work, const u8 inNetID, const u16 inResult);
extern int PTFrame_GetEvtResultOrg(PKTHLN_PTR work, const u8 inNetID);
extern int PTFrame_GetEvtResult(PKTHLN_PTR work, const u8 inNetID);

//シーケンス管理関数群
extern void PTFrame_SetNextFuncTblIdx(PKTHLN_PTR work, const int inIndex);
void PTFrame_SetNextFuncTblIdxByCnd(PKTHLN_PTR work, const int inIndex, const int inCndIndex);
extern void PTFrame_SetSynchroID(PKTHLN_PTR work, const int inID);

//競技結果関連
/**
extern void PTFrame_SetupResultData(PKTHLN_PTR work, const int inDataNum, const BOOL inIconFlg);
extern RESULT_DATA *PTFrame_GetResultData(PKTHLN_PTR work, const u8 inIdx);
extern int PTFrame_GetResultDataNum(PKTHLN_PTR work);
extern BOOL PTFrame_IsValidPokeIcon(PKTHLN_PTR work);
*/
extern void PTFrame_SetDefaultVBlankFunc(GF_BGL_INI *bgl);
extern RSLT_PTR PTFrame_GetResultPtr(PKTHLN_PTR work);

//ポケスロン参加ポケパラメータ関連
extern const int PTFrame_GetPokeParamArcIdx(const int inMonsNo, const int inForm);
extern void PTFrame_SetPkthlnParam(PKTHLN_PTR work);
extern const PKTHPOKE_PARAM *PTFrame_GetPkthlnParam(PKTHLN_PTR work, const int inNetID, const int inEntryNo);
extern void PTFrame_SetMonsInfo(PKTHLN_PTR work, const int inNetID, const int inEntryNo, MONS_INFO *outInfo);
extern const POKE_SPEC *PTFrame_GetPokeSpec(PKTHLN_PTR work, const int inNetID, const int inEntryNo);

extern const int PTFrame_GetPokeTouchRange(void);
extern const  SHADOW_POS PTFrame_GetPokeShdwPosType(const PKTHPOKE_PARAM *inParam);
extern const HIT_TYPE PTFrame_GetPokeHitType(const PKTHPOKE_PARAM *inParam);

//カウントダウン関連
extern CLACT_WORK_PTR *PTFrame_SetCountDownByClSet( PKTHLN_PTR work,
									  				const s16 inYOfs,
													CMN_RES_CNT_PTR cmm_res_ptr,
									  				CLACT_SET_PTR cl_set_ptr);
extern CLACT_WORK_PTR *PTFrame_SetCountDown( PKTHLN_PTR work,
									  const s16 inYOfs,
									  CMN_RES_CNT_PTR cmm_res_ptr,
									  PKTHLN_CLACT_CNT_PTR act_cnt_ptr );
extern void PTFrame_DispLastCount(PKTHLN_PTR work, const int inTime);
//ペンアクター関連
extern void PTFrame_SetPenByClSet( 	PKTHLN_PTR work, const s16 inYOfs,
						   			CMN_RES_CNT_PTR cmm_res_ptr,
						   			CLACT_SET_PTR  cl_set_ptr,
						   			const int inVramType,
						   			const u8 inNum,
						   			const PEN_POS *inPosAry	);

extern void PTFrame_SetPen( PKTHLN_PTR work, const s16 inYOfs,
							CMN_RES_CNT_PTR cmm_res_ptr,
							PKTHLN_CLACT_CNT_PTR act_cnt_ptr,
							const int inVramType,
							const u8 inNum,
							const PEN_POS *inPosAry	);
//▼マーカー関連
extern void PTFrame_InitPosMarker(PKTHLN_PTR work);
extern CLACT_WORK_PTR PTFrame_SetPosMarker( PKTHLN_PTR work, POKE_ACT_PTR pPokePtr,
						   					CMN_RES_CNT_PTR pResCntPtr,
						   		  			CLACT_SET_PTR  pClActSetPtr,
											const int inBGPriority);
extern void PTFrame_EndPosMarker(PKTHLN_PTR work);
extern void PTFrame_ChgPosMarker( PKTHLN_PTR work, const u8 inIdx, const u8 inAnmNo );
extern void PTFrame_StopPosMarker(PKTHLN_PTR work);

extern BOOL PTFrame_CountDown(PKTHLN_PTR work);
extern void PTFrame_SetRecBGMask(PKTHLN_PTR work, const int inRecBGMask);
extern BOOL PTFrame_DispEnd(PKTHLN_PTR work);
extern CLACT_WORK_PTR *PTFrame_GetCountDownActAdr(PKTHLN_PTR work);

extern void PTFrame_AddActionPoint(	PKTHLN_PTR work,
									const u8 inNetID, const u8 inPokeIdx,
									const ACTION_ADD_TYPE inAddType, const int inAddVal	);
extern void PTFrame_SetCheckRecord(PKTHLN_PTR work, const u16 inRecord);
extern void PTFrame_SetRecordCallBack(PKTHLN_PTR work, REC_CALL_BACK func);

extern u16 PTFrame_GetNpcObjCode(const u8 inNpcCode);
extern u32 PTFrame_GetNpcMsgIdx(PKTHLN_PTR work, const u8 inNpcCode);
extern void PTFrame_MakeNPCData(PKTHLN_PTR ptr, const u8 inNum);

extern void *PTFrame_GetJuiceDataAdr(PKTHLN_PTR ptr);
extern void *PTFrame_GetAllJuiceDataAdr(PKTHLN_PTR ptr, const u8 inNetID);

extern BOOL PTFrame_CheckTouchRange( const int inPX1, const int inPY1, const int inPX2, const int inPY2,
							  		 const int inRange, fx32 *outRange);
#endif	//__POKETHLON_H__
